package map;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class HashMapDemo1 {
    public static void main(String[] args) {
        HashMap<String,String> map=new HashMap<>();
        map.put("张三","北京");
        map.put("李四","上海");
        map.put("王五","武汉");
        map.put("赵六","成都");
        System.out.println("map的长度是："+map.size());
        System.out.println("map是否为空:"+map.isEmpty());
        method1(map);
        method2(map);

        Set<Map.Entry<String,String>> entrySet=map.entrySet();
        for (Map.Entry<String, String> stringStringEntry : entrySet) {
            System.out.println(stringStringEntry.getKey()+"---"+stringStringEntry.getValue());
        }
        method3(map);

    }

    private static void method3(HashMap<String, String> map) {
        map.forEach((key, value) -> System.out.println(key+"----"+value));
    }

    private static void method1(HashMap<String, String> map) {
        //        1、获取所有键
        final var strings = map.keySet();
        System.out.println("获取map所有的键："+ strings);
//       2、增强for循环进行遍历
        for (String key : strings) {
            System.out.println("每个键是："+key);
            System.out.println(key+"对应值："+ map.get(key));
        }
        final var string2= map.keySet();
        for (String key2 : string2) {
            System.out.println(key2+"键的值是："+ map.get(key2));

        }
//        通过键值对获取所有对象
        method2(map);

    }

    private static void method2(HashMap<String, String> map) {
        final var entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            System.out.println("在method2方法中，map的键是:"+entry.getKey()+",值是:"+entry.getValue());

        }
    }


}
